﻿@using NewsMine.DomainObjects;

@helper GetFeedItemHtml(NewsMine.DomainObjects.FeedItem feedItem)
    {
<div style="border-bottom: 0px solid #F4F4F4; margin-top: 10px; margin-bottom: 6px;
                        background-color: #FcFcFc;">
                        <table>
                            <tbody><tr>
                                <td style="width:150px; padding: 10px; vertical-align: text-top;">
                                    <img src="https://plus.google.com/_/favicon?alt=feed&amp;domain=@feedItem.Domain " alt="hindi.in.com">
                                    <img style="border-radius:25px;" src="@feedItem.ImageUrl" width="150px;">
                                </td>
                                <td>
                                    <div style="margin-left: 5px">
                                        <a class="name" style="text-decoration: none;" href="@feedItem.Link">
                                            <div style="overflow: hidden; line-height: 1.6; height: auto; font-size: 20px; color: #1F57A5">
                                                @feedItem.Title
                                            </div>
                                        </a>
                                        
                                        <p>@feedItem.category</p>
                                        <p>@feedItem.RefUrl</p>
                                        <p>@feedItem.PubDate</p>

                                        
                                    </div>
                                </td>
                            </tr>
                        </tbody></table>
                    </div>

}

@helper DisplayTest()
    {
    <h1>just for test</h1>
}


 @helper  WelcomeMessage(string username)
     {
    <p>Welcome, @username.</p>
}

@helper DisplayOopsMessage(System.Web.Mvc.WebViewPage vp)
    {
    <div style="background-color:#fff;margin:10px;padding-bottom:10px;">
    <table>
    <tr>
       
    <td> <img src="@vp.Url.Content("~/content/img/pgnotfound.jpg")" alt="feed not found" />
    </td>
    <td><div style="font-size: 20px;color:red;margin:10px;">
            <p>OOPS... some thing wrong with this. Try selecting other news source please... </p>
            Happy
            News Reading....</div>
    
    </td>
    </tr>
    </table>
    </div>
}


@helper DisplayFeeds(List<FeedItem> feeds, System.Web.Mvc.WebViewPage pv)
    {

        string tempTitle = string.Empty;
        string truncatedTitle = string.Empty;

        bool isAdminPortal = true;
        bool IsImageDisplayEnabled = true;


        for (int i = 0; i < feeds.Count; i++)
        {
            feeds[i].Title = System.Text.RegularExpressions.Regex.Replace(feeds[i].Title, @"\s+", " ");
            tempTitle = feeds[i].Title;

            if (!string.IsNullOrEmpty(tempTitle))
            {
                tempTitle = tempTitle.Replace("+", "-");
                tempTitle = NewsMine.Utilities.Extensions.TruncateAtWord(tempTitle, 70);
                tempTitle = HttpUtility.UrlEncode(tempTitle.Replace("+", "-"));
            }

            truncatedTitle = feeds[i].Title;
            int titleDisplaySize = 70;
            if (!string.IsNullOrEmpty(truncatedTitle))
            {
                truncatedTitle = NewsMine.Utilities.Extensions.TruncateAtWord(truncatedTitle, titleDisplaySize);
            }

            // this is temp fix, for one of the malayalam channel.
            if (truncatedTitle.Contains("<!--") || truncatedTitle.Contains(".popover();")
                || truncatedTitle.StartsWith("आगे »")
                )
            {
                continue;
            }


            int reminder = i % 10;
            Random rnd = new Random(i * i);
            int minValue = 80;
            int gapValue = 200 - minValue;

            string temp = (minValue + rnd.Next(reminder, gapValue)).ToString() + "," +
                (minValue + rnd.Next(reminder, gapValue)).ToString() + "," +
                (minValue + rnd.Next(reminder, gapValue)).ToString();
            //string colorWithTrans = "rgba(" + (minValue + rnd.Next(reminder, gapValue)).ToString() + "," +
            //   (minValue + rnd.Next(reminder, gapValue)).ToString() + "," +
            //   (minValue + rnd.Next(reminder, gapValue)).ToString() + ",0.9)";

            string color = "rgb(" + temp + ")";
            string colorWithTrans = "rgba(" + temp + ",0.7)";

            //string targetLink = "/go?t=" + HttpUtility.UrlEncode(tempTitle) + "&u=" + HttpUtility.UrlEncode(feeds[i].Link) + "&id=" + @feeds[i].ID.ToString();
            string targetLink = "/go?id=" + @feeds[i].ID.ToString();

            if (!NewsMine.DataManagers.KeyWordManager.IsDomainSupportsIframe(feeds[i].Domain))
            {
                targetLink = targetLink + "&ni=y";
            }

            int imageHeight = feeds[i].ImageHeight;
            int imageWidth = feeds[i].ImageWidth;


        
        <div class="grid newsItemBox" style="border:1px solid lightgrey;width:100%;">
        <div style="background-color:@color;height:3px;"></div>

     @DisplayTitleAndImage1(truncatedTitle, IsImageDisplayEnabled, targetLink, feeds[i], pv)


     <div class="newsItemBoxFooterBox">
        <span>
         <a style="text-decoration: none;color:#888;" title="more from @feeds[i].Domain ..." href="/source/@feeds[i].Domain">
         <img src="https://plus.google.com/_/favicon?alt=feed&amp;domain=@feeds[i].Domain" style="height:20px;width:20px;" alt="@feeds[i].Domain"/>
          @feeds[i].Domain</a>
          </span>
         <span class="pull-right"> <span class="icon-time"></span><span class="timeago" style="color:#f77;margin-left:2px;" title="@feeds[i].PubDate.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'")">@feeds[i].PubDate.AddHours(5).AddMinutes(30).ToString("dd/MM/yyyy hh:mm tt")</span></span>
        </div>
         
	</div>
        }
        }



@helper DisplayTitleAndImage1(string truncatedTitle, bool IsImageDisplayEnabled, string targetLink, FeedItem feed, System.Web.Mvc.WebViewPage pv)
    {
    <div  class="newsItemTitleBox">
        <a class="name newsItemTitleAnchorTag" target="_blank" href="@targetLink" rel="nofollow">
         <span> @pv.Html.Raw(truncatedTitle) </span>
           @if (!string.IsNullOrEmpty(feed.ImageUrl) && IsImageDisplayEnabled)
           {
		        <div class="imgholder newsItemImageBox">

               <img class="newsItemImage" data-original="@feed.ImageUrl"  src="/Content/img/grey.gif" w="@feed.ImageWidth" h="@feed.ImageHeight" />
		        </div>
           }
           

     </a></div>
}

@helper DisplayTitleOnly(string truncatedTitle, bool IsImageDisplayEnabled, string targetLink, FeedItem feed, System.Web.Mvc.WebViewPage pv, int index)
    {
        string fbUrl = "https://www.facebook.com/sharer/sharer.php?u=" + HttpUtility.UrlEncode("http://www.lookatnews.com/go?id=" + feed.ID.ToString());
        

    <div  class="newsItemTitleBox">
     <img src="https://plus.google.com/_/favicon?alt=feed&amp;domain=@feed.Domain" style="height:16px;width:16px;opacity: 0.4;" alt="@feed.Domain"/>
        <a class="name newsItemTitleAnchorTag" target="_blank" href="@targetLink" rel="nofollow">
         <span> @pv.Html.Raw(truncatedTitle) </span>
     </a>
        <span style="font-size:12px;"> <span class="icon-time"></span><span class="timeago" style="color:#aaa;margin-left:2px;" title="@feed.PubDate.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'")">@feed.PubDate.AddHours(5).AddMinutes(30).ToString("dd/MM/yyyy hh:mm tt")</span></span>
       <a class="name newsItemImageAnchor" title="Publish in facebook" target="_blank" href="@fbUrl">
              <span style="vertical-align:middle;" class="icon-thumbs-up" ></span>
              </a>
     </div>
}


@helper DisplayFeedsByGroup(List<WebApp1.Controllers.FeedGroup> fGroupList, System.Web.Mvc.WebViewPage pv)
    {

        string tempTitle = string.Empty;
        string truncatedTitle = string.Empty;

        bool isAdminPortal = true;
        bool IsImageDisplayEnabled = true;
        int k = 0;
        int j = 3;

        foreach (var item in fGroupList)
        {
            var fGroup = item;
            var feeds = fGroup.Feeds;

            if (fGroup.Score == 0)
            {
                feeds = (from f in feeds orderby f.PubDate descending select f).ToList();
            }

            int reminder = k++ % 10;
            Random rnd = new Random(j * k);
            int minValue = 80;
            int gapValue = 200 - minValue;

            string temp = (minValue + rnd.Next(reminder, gapValue)).ToString() + "," +
                (minValue + rnd.Next(reminder, gapValue)).ToString() + "," +
                (minValue + rnd.Next(reminder, gapValue)).ToString();
            //string colorWithTrans = "rgba(" + (minValue + rnd.Next(reminder, gapValue)).ToString() + "," +
            //   (minValue + rnd.Next(reminder, gapValue)).ToString() + "," +
            //   (minValue + rnd.Next(reminder, gapValue)).ToString() + ",0.9)";

            string color = "rgb(" + temp + ")";
            string colorWithTrans = "rgba(" + temp + ",0.7)";
        
    
       <div class="grid newsItemBox" style="border:1px solid lightgrey;width:100%;">
        <div style="background-color:@color;height:3px;"></div>
         @*@fGroup.Score*@

         <div class="newsItemBoxFooterBox">
        <span>
         <a style="text-decoration: none;color:#888;" title="more from @fGroup.Domain ..." href="/source/@fGroup.Domain">
         <img src="https://plus.google.com/_/favicon?alt=feed&amp;domain=@fGroup.Domain" style="height:20px;width:20px;" alt="@fGroup.Domain"/>
          @fGroup.Domain</a>
          </span>
         <span class="pull-right"> <span class="icon-time"></span><span style="color:#aaa;margin-left:2px;">@fGroup.Date.ToShortDateString()</span></span>
         
        </div>
    

       

      

          @* <div class="nano has-scrollbar" style="height:300px;">
           <div class="content">
           </div></div>*@


               @if (!string.IsNullOrEmpty(fGroup.ImageUrl) && (fGroup.ImageWidth > 40 || fGroup.ImageWidth == 0) && IsImageDisplayEnabled)
               {
                   string leftpull = string.Empty;
                   string clearWidthStyle = string.Empty;

                   if (fGroup.ImageWidth < 150 && fGroup.ImageWidth > 20)
                   {
                       leftpull = "pull-left";
                       clearWidthStyle = "min-width:" + (fGroup.ImageWidth + 20) + "px;";
                   }
                   
                   
              <div class="imgholder newsItemImageBox @leftpull" style="@clearWidthStyle;">
               <img class="newsItemImage"  data-original="@fGroup.ImageUrl"  src="/Content/img/grey.gif" w="@fGroup.ImageWidth" h="@fGroup.ImageHeight" />
            </div>
               }
           
            @if (IsImageDisplayEnabled && (string.IsNullOrEmpty(fGroup.ImageUrl) || (fGroup.ImageWidth > 0 && fGroup.ImageWidth < 40)))
            {
                var webSiteinfo = NewsMine.DataManagers.WebSiteInfoManager.GetDomainByDomainName(fGroup.Domain);

                if (webSiteinfo != null && !string.IsNullOrEmpty(webSiteinfo.Logo1Uri))
                {


                    fGroup.ImageUrl = webSiteinfo.Logo1Uri;
                       <div class="imgholder newsItemImageBox">
                 
                        <a href="/source/@webSiteinfo.Domain" title="more from @webSiteinfo.Name"> 
                        <img class="newsItemImage" data-original="@fGroup.ImageUrl"  src="/Content/img/grey.gif" style="max-height:100px;" />
                    </a>
                    </div>
                    
                }


            }
            
    @for (int i = 0; i < feeds.Count; i++)
    {
        feeds[i].Title = System.Text.RegularExpressions.Regex.Replace(feeds[i].Title, @"\s+", " ");
        tempTitle = feeds[i].Title;

        if (!string.IsNullOrEmpty(tempTitle))
        {
            tempTitle = tempTitle.Replace("+", "-");
            tempTitle = NewsMine.Utilities.Extensions.TruncateAtWord(tempTitle, 70);
            tempTitle = HttpUtility.UrlEncode(tempTitle.Replace("+", "-"));
        }

        truncatedTitle = feeds[i].Title;
        int titleDisplaySize = 70;
        if (!string.IsNullOrEmpty(truncatedTitle))
        {
            truncatedTitle = NewsMine.Utilities.Extensions.TruncateAtWord(truncatedTitle, titleDisplaySize);
        }

        //string targetLink = "/go?t=" + HttpUtility.UrlEncode(tempTitle) + "&u=" + HttpUtility.UrlEncode(feeds[i].Link) + "&id=" + @feeds[i].ID.ToString();

        string targetLink = "/go?id=" + @feeds[i].ID.ToString();
        if (!NewsMine.DataManagers.KeyWordManager.IsDomainSupportsIframe(feeds[i].Domain))
        {
            targetLink = targetLink + "&ni=y";
        }

        int imageHeight = feeds[i].ImageHeight;
        int imageWidth = feeds[i].ImageWidth;

        string bgColor = "#fff;";

        if (i % 2 == 1)
        {
            bgColor = "#F7F7FC";
            //bgColor = "#FbFbFF";
        }
        //bgColor = "#fff;";
        <div style="background-color:@bgColor;">
     @DisplayTitleOnly(truncatedTitle, IsImageDisplayEnabled, targetLink, feeds[i], pv, i)
     </div>
        @*<hr style="height:1px;margin:0px;"/>*@
       

     
    }

   
         
         @*<div style="background-color:@color;height:3px;"></div>*@
	</div>
        }
    
   

        }


       